class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        int left1 = 0, left2 = 0, right1 = nums.size() - 1, right2 = nums.size() - 1;
        if (right1 < 0) return { -1,-1 };
        while (left1 < right1)
        {
            int mid = left1 + (right1 - left1) / 2;
            if (nums[mid] < target)
            {
                left1 = mid + 1;
            }
            else if (nums[mid] >= target)
            {
                right1 = mid;
            }
        }
        while (left2 < right2)
        {
            int mid = left2 + (right2 - left2 + 1) / 2;
            if (nums[mid] <= target)
            {
                left2 = mid;
            }
            else if (nums[mid] > target)
            {
                right2 = mid - 1;
            }
        }
        if (nums[right1] != target && nums[left2] != target) return { -1,-1 };
        return { right1,left2 };
    }
};